import { Component, Input, OnInit } from '@angular/core';
import * as moment from 'moment';
import { OrderType } from 'src/app/constants/order-type';
import { OrderModel } from 'src/app/models/order-model';

@Component({
    selector: 'app-order',
    templateUrl: './order.component.html',
    styleUrls: ['./order.component.sass'],
})
export class OrderComponent implements OnInit {
    @Input()
    order: OrderModel = new OrderModel(OrderType.Xiaomian);

    constructor() {}

    ngOnInit(): void {}

    printOrderTypeName() {
        switch (this.order.type) {
            case OrderType.Xiaomian:
                return '小面';

            case OrderType.Beef:
                return '牛肉面';

            default:
                return '随便';
        }
    }

    printOrderDateCreated() {
        var date = new Date(this.order.dateCreated);
        return 'Ordered ' + moment(date).fromNow();
    }

    printOrderTaken() {
        if (this.order.dateFinished) {
            var takenMilliseconds =
                this.order.dateFinished - this.order.dateCreated;
            return '用时' + takenMilliseconds + '毫秒';
        }

        return '...';
    }
}
